package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * ClassName: ShoppingCartMapper
 * Package:
 * Description
 * 购物车
 * @Author xw
 * @Create 2023/11/23 20:29
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 判断当前加入购物车中的商品是否已经存在了
     * */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 购物车，原有数据+1
     * */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void UpdateNumberByid(ShoppingCart shoppingCart);

    /**
     * 购物车添加数据
     * */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 查看购物车
     * */
    @Select("SELECT * FROM shopping_cart WHERE user_id=#{userId}")
    List<ShoppingCart> showShoppingCart(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * */
    @Delete("DELETE FROM shopping_cart WHERE user_id = #{userid}; ")
    void cleanShoppingCart(Long userid);

    /**
     * 查看菜品数量
     * */
    Integer showNumber(ShoppingCart shoppingCart);

    /**
     * 修改购物车数据
     * */
    @Update("UPDATE shopping_cart SET number = #{number} WHERE user_id = #{userId};")
    void update(ShoppingCart shoppingCart);

    /**
     * 删除单个
     * */
    void deleteNoeShoppingCart(ShoppingCart shoppingCart);
}
